package com.cn.cxq.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.cn.cxq.bean.User;
import com.cn.cxq.exception.sessionTimeOutException;




public class SessionInterceptor extends HandlerInterceptorAdapter {

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		HttpSession sess = request.getSession(false);
		if (request.getRequestURI().endsWith("app/home") || request.getRequestURI().indexOf("app/error/") > 0) {
		} else if (sess != null) {
			User user = (User) sess.getAttribute("user");
			if (user == null || user.name == null) {
				throw new sessionTimeOutException();
			}
		}

		return true;
	}

}
